/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trefliq.EJB.sessionbeans;

import java.util.List;
import javax.annotation.security.PermitAll;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import trefliq.EJB.entities.Media;
import trefliq.EJB.entities.Media;

/**
 *
 * @author YVYAS
 */
@Stateless
@PermitAll
public class MediaBean extends AbstractFacade<Media> {
    @PersistenceContext(unitName = "trefliqPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public MediaBean() {
        super(Media.class);
    }
    
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public void createMedia(String media){
        em.persist(new Media(media));
    }
    
    public String getMediaFromId(Long id){
        Media m = em.createNamedQuery("Media.findById", Media.class).
                    setParameter("id", id).getSingleResult();
        System.out.println("media result = "+ m.toString());
        return m.toString();
    }
    
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public List<Media> getAllMedia(){
        return em.createNamedQuery("Media.findAll", Media.class).getResultList();
    }
    
    
    // AbstractFacade methods.  Copied in to apply security attributes.
    
    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public void create(Media entity) {
        super.create(entity);
    }

    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public void edit(Media entity) {
        super.edit(entity);
    }

    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public void remove(Media entity) {
        super.remove(entity);
    }

    @Override
    public Media find(Object id) {
        return super.find(id);
    }

    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public List<Media> findAll() {
        return super.findAll();
    }

    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public List<Media> findRange(int[] range) {
        return super.findRange(range);
    }

    @Override
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN})
    public int count() {
        return super.count();
    }

}
